import platform = require('../../../../platform/common/baseCommon');
import dbconnector = require('../../../../platform/server/dataService');
import db = require('../../../../platform/server/data');
import appServer = require('../../../../platform/server/appServer');

let webptDataService = new dbconnector.dataTableService();

//公司数据服务地址
webptDataService.serviceUrl = 'http://192.168.5.39:18080/ATSDT_SRV/HS/JsonRpc/SQLForNodeService';
//webptDataService.serviceUrl = 'http://192.168.5.64:8080/ATS5S/HS/JsonRpc/SQLForNodeService';
// thirdService.serviceUrl = 'http://86.36.16.169:8080/ATS55_PT/HS/JsonRpc/SQLForNodeService';
// thirdService.serviceUrl = 'http://86.36.19.15:8080/ATS5S/HS/JsonRpc/SQLForNodeService';

//webptDataService.dbconnect = new dbconnector.dbInfoAndConnands();


//数据库连接信息
// let connectInfo = new dbconnector.connectionInfo('ATS55', 'jdbc:oracle:thin:@192.168.5.30:1521/ats60', 'PAO',
//     '3L2o1ngae3591', 'oracle.jdbc.driver.OracleDriver');

// let connectInfo = new dbconnector.connectionInfo('world', 'jdbc:mysql://localhost:3306/world', 'root',
//     'root', 'com.mysql.jdbc.Driver');

let connectInfo = new dbconnector.connectionInfo('webpt', 'jdbc:oracle:thin:@192.168.5.30/ats60', 'webpt',
    'webpt', 'oracle.jdbc.driver.OracleDriver');

webptDataService.dbConnectInfo = connectInfo;

webptDataService.sqlGenerator = new dbconnector.baseDmlStatementGenerator();

/**
 * 查询用户密码
 */
let cmd_user_password = new db.dataCommandInfo();
cmd_user_password.id = 'cmd_user_password';
cmd_user_password.name = '查询用户密码';
cmd_user_password.sql = `SELECT T.* FROM WEBPT.PT_USER T WHERE{0} `;

let filter_user_password = new db.baseDataFilter()
    .and(
    new db.sqlFilter("ID", "T.ID=?", "用户ID"),
);
cmd_user_password.dataFilter = [];
cmd_user_password.dataFilter.push(filter_user_password);

/**
 * 查询纳税人基本信息
 */
let cmd_user_nsrxx = new db.dataCommandInfo();
cmd_user_nsrxx.id = 'cmd_user_nsrxx';
cmd_user_nsrxx.name = '查询纳税人信息';
cmd_user_nsrxx.sql = `select N.* from SXD_YHNSR T ,TAX_NSRJBXX N where t.djxh=n.djxh and {0}`;

let filter_user_nsrxx = new db.baseDataFilter()
    .and(
    new db.sqlFilter("ID", "T.USERID=?", "用户ID"),
);
cmd_user_nsrxx.dataFilter = [];
cmd_user_nsrxx.dataFilter.push(filter_user_nsrxx);
/**
 * 用户角色信息
 */
let cmd_user_role = new db.dataCommandInfo();
cmd_user_role.id = 'cmd_user_role';
cmd_user_role.name = '用户角色表';
cmd_user_role.sql = `SELECT UR.USER_ID,U.NAME USER_NAME,U.PASSWORD,U.MOBILE,UR.ROLE_ID,R.NAME ROLE_NAME FROM WEBPT.PT_USER U 
join webpt.pt_userrole UR ON U.ID=UR.USER_ID 
join webpt.pt_role R ON UR.ROLE_ID=R.ID WHERE {0}`;
// cmd_user_role.sql = `SELECT ID,NAME,PARENT_ID,DESCRIPTION FROM  WEBPT.PT_ORGANIZATION T WHERE {0} `;
/** 数据过滤器 */
let filter_user_role = new db.baseDataFilter()
    .and(
    new db.sqlFilter("ID", "U.ID=?", "用户ID"),
    new db.sqlFilter("PARENT_ID", "T.PARENT_ID=?", "角色ID"),
    new db.sqlFilter("MOBILE", "U.MOBILE=?", "用户电话号码")
    );
cmd_user_role.dataFilter = [];
cmd_user_role.dataFilter.push(filter_user_role);

/**
 * 根据模块获取特性列表信息
 */
let cmd_featureByModule = new db.dataCommandInfo();
cmd_featureByModule.id = 'cmd_featureByModule';
cmd_featureByModule.name = '根据模块获取特性列表信息';
cmd_featureByModule.sql = `SELECT * FROM WEBPT.PT_FEATURECONTROL T WHERE {0}`;
/** 数据过滤器 */
let filter_featureByModule = new db.baseDataFilter()
    .and(
    new db.sqlFilter("TARGER_ID", "T.TARGER_ID=?", "目标ID"),
    new db.sqlFilter("TARGER_TYPE", "T.TARGER_TYPE=?", "目标类型")
    );
cmd_featureByModule.dataFilter = [];
cmd_featureByModule.dataFilter.push(filter_featureByModule);

/**
 * 纳税人信息
 */
let filter_nsrxx = new db.baseDataFilter()
    .and(new db.sqlFilter("id", "t.id=?", "用户ID相同"));
let cmd_nsrxx = new db.dataCommandInfo();
cmd_nsrxx.id = "cmd_query_xkzzsfpqyfx_nxrxx";
cmd_nsrxx.sql = `select * from webpt.pt_user`;
cmd_nsrxx.dataFilter = [];





webptDataService.commandList = [cmd_user_role, cmd_featureByModule, cmd_nsrxx, cmd_user_password, cmd_user_nsrxx];

//加到服务列表
platform.fetchAddonProtoType(webptDataService);
export let dataServiceInfo = new appServer.serviceInfo();
dataServiceInfo.serviceName = "webptDataService";
dataServiceInfo.serviceObject = webptDataService;







